<?php
// function __autoload($class_name) {
//         include 'class.' . strtolower($class_name) . '.php';
//     }
require_once('class.database.php');

class LiburDao {    

    public function cekLibur($tgl_libur){
        $db=Database::getInstance();
        $con=$db->getConnection(1);

        $query="SELECT * FROM t_libur WHERE tgl='$tgl_libur'";

        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }

    public function getLibur($id){
        $db=Database::getInstance();
        $con=$db->getConnection(1);

        $query="SELECT * FROM t_libur WHERE id='$id'";
        //print_r($query);
        $result=$con->prepare($query);
        $result->execute();
 
        if($result->rowCount()==1){
            $data=$result->fetch();
            return $data;
        }

        return false;
    }

    public function getAllLibur(){
        $db=Database::getInstance();
        $con=$db->getConnection(1);
        $query="SELECT * FROM t_libur";
        
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()>=1){
            return $result->fetchAll();
        }

        return false;
    }

    public function getAllByTahun($tahun){
        $db=Database::getInstance();
        $con=$db->getConnection(1);
        $query="SELECT * FROM t_libur WHERE tahun='$tahun'";
        
        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()>=1){
            return $result->fetchAll();
        }

        return false;
    }


    public function createLibur(Libur $libur){
        $db= Database::getInstance();
        $con=$db->getConnection(1);


        $query="INSERT INTO t_libur(tgl,idHari,uraian,tahun) ";
        $query.=" VALUES('$libur->tgl_libur','$libur->idHari','$libur->uraian','$libur->tahun')";

        //print_r($query);

        //$data=array($user->nip,$password,$user->id_parent_user,$user->id_kewenangan,$date_created,$user->user_creating);

        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }

    public function deleteLibur($id){
        $db=Database::getInstance();
        $con=$db->getConnection(1);

        $query="DELETE FROM t_libur WHERE id='$id'";

        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }

    public function updateLibur(Libur $libur){
        $db=Database::getInstance();
        $con=$db->getConnection(1);

        $query="UPDATE t_libur SET tgl='$libur->tgl_libur',idHari='$libur->idHari', uraian='$libur->uraian',tahun='$libur->tahun' 
        	 WHERE id='$libur->id'";

        $result=$con->prepare($query);
        $result->execute();

        if($result->rowCount()==1){
            return true;
        }

        return false;
    }

}


class Libur {
	var $id;
    var $idHari;
	var $tgl_libur;
	var $uraian;
	var $tahun;
}
?>